<template>
	<view class="wrap">
		<view class="card cardTop">
			<view class="title">{{regnoInfo.entname}}</view>
			<view class="con">统一社会信用代码/注册号：{{regnoInfo.regno}}</view>
			<view class="text">
				<text>{{year}}度年报信息</text>
				<!-- <text :style="(state==='01'||state==='02'||state==='03')?'color: #00C260;':'color: red;'">{{$util.stateText(state)}}</text> -->
				<!-- 更改为不超时皆可填写↓↓↓ -->
				<text :style="state==='02'?'color: #00C260;':'color: red;'">{{$util.stateText(state)}}</text>
			</view>
			<view class="selectYear">
				<view class="btn">
					<u-button :disabled="!$util.submitState(year,state)" text="关联过去年度信息" color="#A67315" size="small" @click="select()"></u-button>
				</view>
			</view>
			
		</view>
		
		<!-- 小表单 -->
		<template>
			<view v-if="formList.overduepay" class="card cardList" @click="goForm('/pages/annalsForm/overduepay')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.overduepay]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.overduepay]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.overduepay]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>逾期尚未支付合同情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.baseinfo" class="card cardList" @click="goForm('/pages/annalsForm/baseinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.baseinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.baseinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.baseinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>基本信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.subcapital" class="card cardList" @click="goForm('/pages/annalsForm/subcapital')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.subcapital]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.subcapital]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.subcapital]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>股东及出资信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.empnum" class="card cardList" @click="goForm('/pages/annalsForm/empnum')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.empnum]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.empnum]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.empnum]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>从业人数（其中）</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.websiteinfo" class="card cardList" @click="goForm('/pages/annalsForm/websiteinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.websiteinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.websiteinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.websiteinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>网站或网店信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.sfcBranchinfo" class="card cardList" @click="goForm('/pages/annalsForm/sfcBranchinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.sfcBranchinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.sfcBranchinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.sfcBranchinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>分支机构情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.alterstockinfo" class="card cardList" @click="goForm('/pages/annalsForm/alterstockinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.alterstockinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.alterstockinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.alterstockinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>股权变更信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.forinvestment" class="card cardList" @click="goForm('/pages/annalsForm/forinvestment')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.forinvestment]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.forinvestment]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.forinvestment]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>对外投资信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.assetinfo" class="card cardList" @click="goForm('/pages/annalsForm/assetinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.assetinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.assetinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.assetinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>资产状况信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.sfcLicenceinfo" class="card cardList" @click="goForm('/pages/annalsForm/sfcLicenceinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.sfcLicenceinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.sfcLicenceinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.sfcLicenceinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>行政许可信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.forguaranteeinfo" class="card cardList" @click="goForm('/pages/annalsForm/forguaranteeinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.forguaranteeinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.forguaranteeinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.forguaranteeinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>对外担保信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.socsecinfo" class="card cardList" @click="goForm('/pages/annalsForm/socsecinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.socsecinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.socsecinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.socsecinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>社保信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.partybuilding" class="card cardList" @click="goForm('/pages/annalsForm/partybuilding')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.partybuilding]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.partybuilding]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.partybuilding]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>党建信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			
			<view v-if="formList.cuEntreginfo" class="card cardList" @click="goForm('/pages/annalsForm/cuEntreginfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.cuEntreginfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.cuEntreginfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.cuEntreginfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>报关信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.wsBaseinfo" class="card cardList" @click="goForm('/pages/annalsForm/wsBaseinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.wsBaseinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.wsBaseinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.wsBaseinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>外商投资基本情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.wsSubcapital" class="card cardList" @click="goForm('/pages/annalsForm/wsSubcapital')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.wsSubcapital]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.wsSubcapital]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.wsSubcapital]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>投资者信息</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.operateinfo" class="card cardList" @click="goForm('/pages/annalsForm/operateinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.operateinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.operateinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.operateinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>外商投资经营情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.debtinfo" class="card cardList" @click="goForm('/pages/annalsForm/debtinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.debtinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.debtinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.debtinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>债权、债务情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.dutyFreeinfo" class="card cardList" @click="goForm('/pages/annalsForm/dutyFreeinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.dutyFreeinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.dutyFreeinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.dutyFreeinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>进口设备减免税情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			<view v-if="formList.assetsLiabilitiesinfo" class="card cardList" @click="goForm('/pages/annalsForm/assetsLiabilitiesinfo')">
				<view class="left">
					<uni-icons :type="stateAll[minFormType.assetsLiabilitiesinfo]?'checkmarkempty':'info-filled'" :color="stateAll[minFormType.assetsLiabilitiesinfo]?'#00C260':'#F95151'" size="22"></uni-icons>
					<text>{{stateAll[minFormType.assetsLiabilitiesinfo]?'已填写':'未填写'}}</text>
				</view>
				<view class="right">
					<text>资产负债情况</text>
					<uni-icons type="right" size="24"></uni-icons>
				</view>
			</view>
			
		</template>
		
		
		<view class="submitBtn_bc"></view>
		<view class="submitBtn_ubtn">
			<u-button :disabled="!submitBtnSta" @click="submitBtn()">{{$util.submitState(year,state)?'预览':'查看年报'}}</u-button>
		</view>
		
		
		<uni-popup ref="pop">
			<view class="popWrap">
				<view class="title">年报信息关联</view>
				<view class="pop_con">
					<view class="pop_con_text">选择年度：</view>
					<view class="pop_con_sel">
						<uni-data-select
							v-model="type"
							:localdata="list"
							@change="yearChange"
						></uni-data-select>
					</view>
				</view>
				<view class="button">
					<view class="cancel" @click="popClose()">取消</view>
					<view class="confirm" @click="fillBtn()">确认</view>
				</view>
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
export default {
	data(){
		return{
			imgDomain: this.$config.imgDomain,
			regnoInfo: this.$store.state.regnoInfo,
			year: '',
			state: '',
			
			// 导入
			list: [],
			type: '',
			fillData: {},
			fillYear: '',
			
			// 按钮状态——待修改
			submitBtnSta: false,
			
			
			// -----------------新逻辑-----------------
			formList: [], //表单内容
			minFormType: [], //小表单类型值
			stateAll: [], //状态
			
		}
	},
	onLoad(option) {
		this.year = option.year;
		this.state = option.state;
		this.getFormList();
	},
	onShow() {
		// if(this.state==='01'||this.state==='02'||this.state==='03'){
		// 更改为不超时皆可填写↓↓↓
		if(this.state==='02'){
			// 已公示了的，全部填写为已填写
			this.allFillInState();
		}else{
			this.getRecord();
		}
	},
	methods:{
		// 拿到企业类型拥有的小表单
		getFormList(){
			let typeList = this.$typeList();
			let obj = typeList.get(this.regnoInfo.enttype);
			// let obj = typeList.get('大型企业');
			let keys = Object.keys(obj);
			this.formList = obj;
			this.formKeys = keys;
			
			let minFormType = {};
			keys.forEach(item=>{
				minFormType[item] = this.$minFormType.get(item);
			})
			this.minFormType = minFormType;
		},
		
		// 获取填写状态
		getRecord(){
			this.$http.sendRequest({
				url: '/annual/report/record',
				data: {
					regno: this.regnoInfo.regno,
					year: this.year
				}
			})
			.then(res=>{
				if(res.data){
					let arr = res.data.fillingItem.split(',');
					let obj = {};
					arr.forEach(item=>{
						obj[item] = true;
					})
					this.stateAll = obj;
				}else{
					this.stateAll = {};
				}
				this.upDataSubmitSta();
			})
			.catch(err=>{
				this.stateAll = {};
			})
		},
		//  更新按钮状态
		upDataSubmitSta(){
			let values = Object.values(this.minFormType);
			let sta = true;
			values.forEach(item=>{
				if(!this.stateAll[item]){
					sta = false;
				}
			})
			this.submitBtnSta = sta;
		},
		// 已公示的，更改为全部已填写
		allFillInState(){
			let values = Object.values(this.minFormType);
			values.forEach(item=>{
				this.stateAll[item] = true;
			})
			this.submitBtnSta = true;
		},
		
		// 预览并提交 / 查看年报
		submitBtn(){
			// 先校验确认是否已经全部填报
			this.$util.showToast({title:'前往预览页'})
			
			if(this.$util.submitState(this.year,this.state)){
				// 预览并提交
			}else{
				// 查看年报
			}
			
			let url = `/pages/annals/preview?year=${this.year}&state=${this.state}`
			uni.navigateTo({
				url: url
			})
		},
		
		//存一下记录
		setRecord(fillingItem){
			this.$http.sendRequest({
				url: '/annual/report/record',
				method: 'POST',
				data: {
					regno: this.regnoInfo.regno,
					year: this.year,
					fillingItem: fillingItem,
					isImp: '1',
				},
				hideLoad: true,
			})
			.then(res=>{
				this.getRecord();
			})
			.catch(err=>{})
		},
		
		// 选择导入
		fillBtn(){
			let _this = this;
			if(this.type){
				
				// 调用导入复制
				this.$http.sendRequest({
					url: '/annual/report/baseinfo/imp',
					data:{
						regno: this.regnoInfo.regno,
						impAncheyear: this.fillYear,
						targetAncheyear: this.year,
						enttype: this.regnoInfo.enttype,
					},
				})
				.then(res=>{
					if(res.data){
						let data = res.data;
						let keys = Object.keys(data);
						let fillingItemArr = [];
						keys.forEach(item=>{
							if(data[item]){
								let fillingItem = _this.$minFormType.get(item)
								fillingItemArr.push(fillingItem);
							}
						})
						let fillingItemStr = fillingItemArr.join(',');
						_this.setRecord(fillingItemStr);
					}
					this.popClose();
				})
				.catch(err=>{})
				
			}else{
				this.$util.showToast({title: '请先选择年度'});
			}
		},
		// 选择导入选择的年度
		yearChange(e){
			let arr = this.list;
			for(let i=0; i<arr.length; i++){
				if(arr[i].ancheyear == this.type){
					this.fillData = arr[i];
					this.fillYear = arr[i].ancheyear;
					break;
				}
			}
		},
		popClose(){
			this.$refs.pop.close();
		},
		//打开导入列表弹窗
		select(){
			this.$http.sendRequest({
				url: '/annual/report/baseinfo/list',
				data: {
					regno: this.regnoInfo.regno,
				}
			})
			.then(res=>{
				let arr = [];
				if(res.data.length>0){
					res.data.forEach(item=>{
						item.text = item.ancheyear;
						item.value = item.ancheyear;
						if(item.ancheyear != this.year && item.state == '02'){
							arr.push(item);
						}
					})
					if(arr.length>0){
						this.list = arr.reverse();
						this.$refs.pop.open();
					}else{
						this.$util.requestToast({title: '暂无数据！'})
					}
				}else{
					this.$util.requestToast({title: '暂无数据！'})
				}
			})
			.catch(err=>{})
		},
		goForm(path){
			let url = `${path}?year=${this.year}&state=${this.state}`
			uni.navigateTo({
				url: url
			})
		},
	}
}
</script>

<style lang="less" scoped>
.wrap{
	width: 100vw;
	min-height: 100vh;
	padding-top: 16rpx;
	box-sizing: border-box;
	background-color: #F5F6F8;
	position: relative;
}
.card{
	width: 100%;
	box-sizing: border-box;
	padding: 16rpx 30rpx;
	background-color: #FFF;
	margin-bottom: 16rpx;
	
	.title{
		min-height: 40rpx;
		font-size: 40rpx;
		font-weight: bold;
		color: #A67315;
		padding-left: 10rpx;
	}
	.con{
		font-size: 26rpx;
		color: #b6b6b6;
		margin-top: 20rpx;
		padding-left: 10rpx;
	}
}
.cardTop{
	.text{
		font-size: 32rpx;
		color: #707070;
		padding: 24rpx 10rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 2rpx solid #E4B269;
		margin-top: 24rpx;
		line-height: 1;
	}
	.btn{
		width: 270rpx;
		height: 64rpx;
		margin-left: 10rpx;
	}
}

.cardList{
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-top: 30rpx;
	padding-bottom: 30rpx;
	padding-right: 20rpx;
	
	.left{
		padding-left: 10rpx;
		display: flex;
		align-items: center;
		
		text{
			font-size: 32rpx;
			color: #707070;
			margin-left: 10rpx;
			position: relative;
			top: -2rpx;
		}
	}
	
	.right{
		display: flex;
		align-items: center;
		
		text{
			font-size: 32rpx;
			color: #707070;
			margin-right: 10rpx;
			position: relative;
			top: -2rpx;
		}
	}
}

.popWrap{
	width: 80vw;
	height: 420rpx;
	background-color: #FFF;
	border-radius: 20rpx;
	position: relative;
	
	.title{
		padding: 30rpx;
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
	}
	
	.pop_con{
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 30rpx 20rpx;
		
		.pop_con_text{
			color: #333;
			font-size: 30rpx;
		}
		.pop_con_sel{
			width: 300rpx;
		}
		
	}
	
	.button{
		width: 100%;
		height: 90rpx;
		position: absolute;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 32rpx;
		font-weight: bold;
		color: #fff;
		border-top: 2rpx solid rgba(0, 0, 0, 0.3);
		
		view{
			width: 50%;
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.cancel{
			border-right: 2rpx solid #fff;
			background-color: #c1c1c1;
			border-radius: 0 0 0 20rpx;
		}
		.confirm{
			background-color: #E4B269;
			border-radius: 0 0 20rpx 0;
		}
	}
}

</style>